//
//  CompetionHomeBottomRewardCell.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/9/21.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "CompetionHomeBottomRewardCell.h"
#import "MatchListModel.h"
@implementation CompetionHomeBottomRewardCell

-(NSString *)timeBackAccoringValue:(NSString *)timestap{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[timestap integerValue]/1000];//现在时间,你可以输出来看下是什么格式
    NSLog(@"这是现%@",confromTimesp);
    NSString *nowtimeStr = [formatter stringFromDate:confromTimesp];
    NSLog(@"这是现在的时间吗%@",nowtimeStr);
    return nowtimeStr;
}
-(void)setModel:(MatchListModel *)model{
    _model = model;
    UIImageView *bgImageView = [[UIImageView alloc] init];
    [self addSubview:bgImageView];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:model.ImgPath] placeholderImage:[UIImage imageNamed:@""]];
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(scaleLeftAndRight(10));
        make.right.equalTo(self.mas_right).offset(scaleLeftAndRight(-10));
        make.top.equalTo(self.mas_top);
        make.height.mas_equalTo(scaleTopAndBottom(140));
    }];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = [UIFont systemFontOfSize:16.0f];
    titleLabel.text = _model.name;
    titleLabel.textColor = COLOR_HEX(0x121212);
    [self addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(scaleLeftAndRight(15));
        make.right.equalTo(self.mas_right).offset(scaleLeftAndRight(-15));
        make.top.equalTo(bgImageView.mas_bottom).offset(scaleTopAndBottom(15));
        make.height.mas_equalTo(scaleTopAndBottom(15));
    }];
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.font = [UIFont systemFontOfSize:13.0f];
    timeLabel.text = [NSString stringWithFormat:@"%@  ",[self timeBackAccoringValue:_model.matchEndTime]];
    timeLabel.textColor = UIColorFromRGB(0x666666);
    [self addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(scaleLeftAndRight(15));
        make.top.equalTo(titleLabel.mas_bottom).offset(scaleTopAndBottom(9));
        make.height.mas_equalTo(scaleTopAndBottom(10));
        make.right.equalTo(self.mas_right).offset(scaleLeftAndRight(-15));
    }];
}

/**
 根据时间戳获取到时间差
 
 */
- (NSString* )getHour:(NSString *)takeCarTime systemTime:(NSString *)systemTime

{
    
    //  时区相差8个小时 加上这个时区即是北京时间
    
    NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
    
    NSInteger delta = [timeZone secondsFromGMT];
    
    NSDate *DRstartDate = [NSDate date];
    NSDate *DRendDate = [[NSDate alloc] initWithTimeIntervalSince1970:[systemTime doubleValue]/1000 + delta];
    NSLog(@"开始时间%@",DRstartDate);
    NSLog(@"结束时间%@",DRendDate);
    // 日历对象 （方便比较两个日期之间的差距）
    
    NSTimeInterval interTime = [DRendDate timeIntervalSinceNow];
    //计算天数、时、分、秒
    
    int days = ((int)interTime)/(3600*24);
    
    int hours = ((int)interTime)%(3600*24)/3600;
    
    int minutes = ((int)interTime)%(3600*24)%3600/60;
    
    NSString *dateContent = [[NSString alloc] initWithFormat:@"倒计时:%i天%i时%i分",days,hours,minutes];
    NSLog(@"嘎嘎嘎嘎%@",dateContent);
    return dateContent;
    
}


@end
